package com.ap.core.validation.message.rules;

import com.ap.core.cxf.jaxb.common.ActivationStatus;
import com.ap.core.dao.DistributorDao;
import com.ap.core.domain.Distributor;
import com.ap.core.validation.message.info.MessageValidationInfo;
import com.ap.core.validation.rules.AbstractValidationRule;

public abstract class AbstractDistributorCheckRule<T,OI> extends AbstractValidationRule<MessageValidationInfo<T,OI>> {
	
	  private DistributorDao distributorDao;
	  
	  protected boolean isDistributorExists(String distributorIdentification){
		  final Distributor distributor = distributorDao.getDistributorByIdentification(distributorIdentification);
	       return null != distributor;
	  }
	  
	  protected boolean isDistributorActive(String distributorIdentification){
		  final Distributor distributor = distributorDao.getDistributorByIdentification(distributorIdentification);
	       return null != distributor && ActivationStatus.ACTIVE == distributor.getActivationStatusCode();
	  }
	  
	  public void setDistributorDao(DistributorDao distributorDao) {
	        this.distributorDao = distributorDao;
	    }

	abstract public boolean validate(MessageValidationInfo<T,OI> infoObject);

}
